<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/4
 * Time: 10:14
 */

use Biz\service\BrandPreFecture;
use Biz\service\ShopMall as sShopMall;
use Biz\service\trade\UserAddress;
use Biz\tools\GoodsExposureLog;
use Doraemon\tools\HhzClient;

/**
 * Class MultipleBannerAction
 * @deprecated
 */
class MultipleBannerAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    const DEFAULT_PAGESIZE = 8;

    public function main()
    {
        $show = 1;
        if (file_exists(BrandPreFecture::RECOMMEND_ONOFF_FILE)) {
            $on_off_json = file_get_contents(BrandPreFecture::RECOMMEND_ONOFF_FILE);
            $on_off_arr = json_decode($on_off_json, true);
            if (isset($on_off_arr['fine_goods_main']) && !(int)$on_off_arr['fine_goods_main']) {
                $show = 0;
            }
        }
        $uid = $this->uid;
        $areaCode = UserAddress::getUserDefaultCityCode($uid);
        $data = sShopMall::multipleBanner($uid, $this->appVersion, $areaCode);
        $brand_list = [];

        if (version_compare(HhzClient::getClientVersion(), "4.10.0", ">=") && $show == 1) {
            //算法推荐品牌列表
            $brand_list = BrandPreFecture::recommendBrands('好物主频道精选品牌', $this->uid);
        }
        $data['brand_list'] = $brand_list;
        if (version_compare(HhzClient::getClientVersion(), "4.10.0", "<=") && isset($data['list'])) {
            unset($data['list']);
        }
        $data = $data ?: (object)$data;
        $this->setSuccess($data);
        GoodsExposureLog::addLog($this->getRequest(), $data);
    }

}